@extends('backstage.layout.master')
@section('title', '资源列表')
@section('content')
    <div class="breadcrumbs" id="breadcrumbs">
        <script type="text/javascript">
            try {
                ace.settings.check('breadcrumbs', 'fixed')
            } catch (e) {
            }
        </script>

        <ul class="breadcrumb">
            <li>
                <i class="icon-home home-icon"></i>
                <a href="backstage/home">主页</a>
            </li>

            <li class="active">
                <a href="backstage/module/module-list">模块管理</a>
            </li>
        </ul><!-- .breadcrumb -->
    </div>

    <div class="page-content">
        <div class="row">
            <div class="col-xs-12">
                <!-- PAGE CONTENT BEGINS -->
                <div class="page-header">
                    <h1>
                        模块管理
                        <small>
                            <i class="icon-double-angle-right"></i>
                            资源列表
                        </small>
                    </h1>
                </div>
                <div class="col-xs-12" style="margin-bottom: 20px;">
                    按所属模块显示:
                    <select name="find_module_id" id="find-module">
                        @foreach($find_modules as $find_module)
                            <option @if($find_module->find_module_id == $find_module_id) selected
                                    @endif value="{{$find_module->find_module_id}}">{{$find_module->find_module_name}}</option>
                        @endforeach
                    </select>
                    <a href="backstage/module/add-data/{{$find_module_id}}">
                        <button class="btn btn-danger add-btn-danger" style="float: right;">添加资源</button>
                    </a>
                </div>

                <div class="table-responsive">
                    <table id="sample-table-1" class="table table-striped table-bordered table-hover">
                        <thead>
                        <tr>
                            <th>降序排列</th>
                            <th class="center">用户ID</th>
                            <th class="center">用户昵称</th>
                            <th class="center">手机号码</th>
                            <th class="center">用户状态</th>
                            <th>操作</th>
                        </tr>
                        </thead>

                        <tbody>
                        @foreach($users as $user)
                        <tr>
                            <td style="width:68px;">
                                <input type="text" name="sort" value="{{$user->sort}}" class="sort"
                                       style="width:50px;" data="{{$user->sort}}"
                                       data-module-id="{{$user->user->user_id}}"
                                       onblur="updateModule(this,2);">

                            </td>
                            <td class="center">{{ $user->user->user_id }}</td>
                            <td class="center">{{ $user->user->nick_name }}</td>
                            <td class="center">{{ $user->user->phone }}</td>
                            <td class="center">
                                {{ $user->user->user_type_name }}
                            </td>
                            <td>
                                <a href="backstage/module/delete-resource/{{$find_module_id}}/{{$user->user->user_id}}" class="red" onclick="return confirm('确认删除吗？');">删除</a>
                            </td>
                        </tr>
                        @endforeach
                        </tbody>
                    </table>
                </div>
                <!-- PAGE CONTENT ENDS -->
            </div><!-- /.col -->
        </div><!-- /.row -->
    </div><!-- /.page-content -->
@stop
@section('script')
    <script type="text/javascript">
        var flag = 1;
        $(function () {
            $("#find-module").change(function(){
                window.location.href="backstage/module/data-list/"+$(this).val();
            });
            $.ajaxSetup({
                headers: {
                    'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                }
            });
        });
        function updateModule(th, type) {
            //修改排序
            var newsort = $(th).val();
            var oldsort = $(th).attr('data');
            if (newsort == oldsort) {
                return false;
            }
            changeSort(th, newsort, $(th).attr("data-module-id"));
        }
        function changeSort(th, sort, resource_id) {
            if (flag == 1) {
                flag = 0;
                $.ajax({
                    type: "POST",
                    url: "backstage/module/update-resource-sort",
                    data: {"sort": sort, "find_module_id": "{{$find_module_id}}","resource_id":resource_id},
                    success: function (msg) {
                        flag = 1;
                        if (msg.state == "M00000") {
                            $(th).attr("data", msg.result.sort);
                            showMessage("", msg.message);
                        } else {
                            showMessage(msg.message, "");
                        }
                    },
                    error: function () {
                        flag = 1;
                        showMessage("修改失败!", "");
                    }
                });
            }
        }
    </script>
@stop